#include<vector>
using namespace std;

class Solution {
public:
    int search(vector<int>& arr, int target) {
        int left = 0, right = arr.size() - 1;
        while (left <= right) {
            while (left < right && arr[left] == arr[right])
                --right;
            int mid = left + (right - left) / 2;
            if (mid > left) {
                int tmp = arr[mid];
                while (mid > left && arr[mid - 1] == tmp)
                    --mid;
            }
            if (target == arr[mid]) return mid;
            if (arr[mid] >= arr[right]) {
                if (target<arr[mid] && target>arr[right])
                    right = mid - 1;
                else
                    left = mid + 1;
            }
            else {
                if (target > arr[mid] && target <= arr[right])
                    left = mid + 1;
                else
                    right = mid - 1;
            }
        }
        return -1;
    }
};

int main() {
    vector<int> arr = { 15, 16, 19, 20, 25, 1, 3, 4, 5, 7, 10, 14 };
    Solution sol;
    sol.search(arr, 5);
}